<template>
  <div>
    <div class="header">
      <cinemasheader></cinemasheader>
    </div>

    <!-- 导航------------------------------------------------------- -->
    <div class="se-nav">
      <div class="nav-item">
        <div
          v-for="(item, index) in list"
          :class="{ active: index == isActives }"
          @click="change(index)"
          :key="item.id"
        >
          {{ item.name }}
        </div>
        <!-- <div @click="change(2)" >
                即将热映
                </div>
                <div @click="change(3)" >
                经典影片
                </div> -->
      </div>
    </div>
    <navigation></navigation>
    <div class="selection">
      <el-radio-group v-model="sort">
        <el-radio :label="1">按热门排序</el-radio>
        <el-radio :label="2">按时间排序</el-radio>
      </el-radio-group>
    </div>
    <div class="movies-list">
      <ul class="movies-list-ul">
        <li
          class="movies-list-li"
          v-for="(item, index) in filmls"
          :key="index"
          @click="toFilmDetail(item.filmId)"
        >
          <div class="movies-list-img">
            <img
              src="https://p1.meituan.net/movie/f6ec2a022d3644ef493f881d359f65303190471.jpg@160w_220h_1e_1c"
              alt=""
            />
            <div class="movie-item-hover">
              <img
                class="movie-hover-img"
                src="https://p1.meituan.net/movie/f6ec2a022d3644ef493f881d359f65303190471.jpg@160w_220h_1e_1c"
                alt=""
              />
              <div class="movie-hover-info">
                <div>{{ item.filmName }}</div>
                <div><span class="hover-tag">类型:</span>剧情／家庭</div>
                <div>
                  <span class="hover-tag">主演:</span
                  >{{ item.filmDirector }}／{{ item.filmPlay }}／朱媛媛
                </div>
                <div>
                  <span class="hover-tag">上映时间:</span
                  >{{ dateFormat("YYYY-mm-dd ", item.filmDate) }}
                </div>
              </div>
            </div>
          </div>
          <p class="movies-list-p">{{ item.filmName }}</p>
          <p class="evaluate" v-if="item.filmTop">{{ item.filmTop }}</p>
          <p class="evaluate" v-else-if="!item.filmTop">暂无评价</p>
        </li>
      </ul>
    </div>
    <homeFooter></homeFooter>
  </div>
</template>
<style lang="scss" scoped>
.header {
  width: 100%;
  height: 80px;
  background: #fff;
  border-bottom: 1px solid #d8d8d8;
}
.se-nav {
  width: 100%;
  height: 60px;
  background: #47464a;

  .nav-item {
    width: 1200px;
    height: 60px;
    // background: skyblue;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-content: center;
    .active {
      color: #ef4238 !important;
    }
    div {
      width: 160px;
      height: 60px;
      float: left;
      text-align: center;
      line-height: 60px;
      //   background: chocolate;
      color: #999;
      font-size: 16px;
      cursor: pointer;
    }

    div:hover {
      color: #fff;
    }

    .active:hover {
      color: #ef4238;
    }
  }
}
.tags-panel {
  width: 1080px;
  border: 1px solid #e5e5e5;
  padding: 0 20px;
  margin: 0 auto;
  margin-top: 40px;

  .tags-panelSpan {
    height: 24px;
    line-height: 24px;
    float: left;
    color: #999;
    font-size: 14px;
  }
  .tags-panelList {
    padding: 10px 0;
    border-bottom: 1px dotted #e5e5e5;
    .tags {
      float: left;
      width: 1000px;
      li {
        color: #333;
        font-size: 14px;
        padding: 3px 9px;
        display: inline-block;
        margin-left: 12px;
      }
      li:nth-child(1) {
        background: #f34d41;
        color: #fff;
        border-radius: 14px;
      }
      .tagsLiActive {
        background: #f34d41;
        color: #fff;
        border-radius: 14px;
      }
    }
    .tags li:hover {
      color: #ef4238;
    }
  }
  div:nth-child(3) {
    border: 0;
  }
}
.selection {
  width: 1120px;
  margin: 40px auto;
  margin-bottom: 40px;
}
.movies-list {
  width: 1120px;
  margin: 0 auto;
  .movies-list-ul {
    width: 100%;
    display: flex;
    flex-flow: wrap;
    // justify-content: space-between;

    .movies-list-li {
      width: 160px;
      text-align: center;
      // margin: 1px;
      font-size: 16px;
      margin-bottom: 32px;
      margin-right: 32px;
      &:nth-child(6n) {
        margin-right: 0;
      }
      .movies-list-img {
        width: 160px;
        height: 220px;
        border: 1px solid #efefef;
        position: relative;
        img {
          width: 100%;
          height: 100%;
        }
        .movie-item-hover {
          display: none;
          position: absolute;
          width: 218px;
          height: 300px;
          z-index: 10;
          top: -40px;
          left: -29px;
          overflow: hidden;
          background: #fff;
          box-shadow: 0 0 16px #fff, 0 0 6px rgba(0, 0, 0, 0.2);
          .movie-hover-img {
            width: 218px;
            height: 300px;
            vertical-align: middle;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 10;
          }
          .movie-hover-info {
            padding: 16px;
            height: 150px;
            box-sizing: border-box;
            position: absolute;
            z-index: 11;
            left: 0;
            top: 150px;
            background: #fff;
            width: 218px;
            div {
              font-size: 16px;
              line-height: 16px;
              color: #999;
              margin-top: 12px;
              width: 100%;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              text-align: left;
              .hover-tag {
                color: #333;
              }
            }
            div:nth-child(1) {
              margin-top: 6px;
              font-size: 20px;
              color: #333;
              line-height: 20px;
              text-align: left;
            }
          }
        }
      }
      .movies-list-img:hover .movie-item-hover {
        display: block;
      }
      .movies-list-p {
        color: #333;
        line-height: 32px;
      }
      .evaluate {
        margin-top: 10px;
        color: #ffb400;
      }
    }
  }
  .paging {
    width: 500px;
    margin: 0 auto;
  }
}
</style>
<script>
import homeFooter from "../components/home/homefooter";
import cinemasheader from "../components/home/header";
import navigation from "../components/films/navigation";
import films from "../model/cinemas";
import bus from "../bus/index";
export default {
  data() {
    return {
      boardIndex: 1,
      radio: 3,
      list: [
        { id: 1, name: "正在热播" },
        { id: 2, name: "即将热映" },
        { id: 3, name: "经典影片" },
      ],
      isActives: false,
      filmls: [], // 渲染电影列表
      type: "", // 按类型筛选
      region: "", // 按地区筛选
      sort: 1, // 按时间排序？
    };
  },
  components: {
    navigation,
    homeFooter,
    cinemasheader,
  },
  created() {
    this.getData();
    // 获取按电影类型筛选
    bus.$on("gettype", (type) => {
      this.type = type == 0 ? "" : type;
      this.getData();
    });
    // 获取按地区筛选
    bus.$on("getregion", (region) => {
      this.region = region == 0 ? "" : region;
      this.getData();
    });
  },

  methods: {
    // 请求数据
    getData() {
      // console.log(this.sort)
      films
        .films({
          "sort.sortId": this.type,
          "language.languageId": this.region,
          type: this.sort,
        })
        .then((res) => {
          //   console.log(res);
          if (res.data.code == "10000") {
            this.filmls = res.data.data.list;
            console.log(this.filmls);
          }
        });
    },
    // 改变 即将上映 / 正在热映
    change(index, item) {
      this.isActives = index;
    },
    // 前往电影详情
    toFilmDetail(id) {
      this.$router.push(`films/${id}`);
    },
    //时间转换
    dateFormat(fmt, date) {
      let ret = "";
      date = new Date(date);
      const opt = {
        "Y+": date.getFullYear().toString(), // 年
        "m+": (date.getMonth() + 1).toString(), // 月
        "d+": date.getDate().toString(), // 日
        "H+": date.getHours().toString(), // 时
        "M+": date.getMinutes().toString(), // 分
        "S+": date.getSeconds().toString(), // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      };
      for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
          fmt = fmt.replace(
            ret[1],
            ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
          );
        }
      }
      return fmt;
    },
  },
  watch: {
    sort: function (val) {
      this.getData();
    },
  },
};
</script>
